﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OpenCAMClient
{
    public partial class frm_main : Form
    {
        public frm_main()
        {
            InitializeComponent();
        }
        Dictionary<string, string> PokemonPathDic = new Dictionary<string, string>();
        Dictionary<string, string> WuXiaPathDic = new Dictionary<string, string>();
        private Button btn_Open = new Button();
        private void frm_main_Load(object sender, EventArgs e)
        {
            string settingPokemonPath = string.Format(@"{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "PokemonPath.txt");
            string settingWuXiaPath = string.Format(@"{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "WuXiaPath.txt");

            using (StreamReader sr = new StreamReader(settingPokemonPath, Encoding.Default))
            {
                string line = string.Empty;
                while (!string.IsNullOrWhiteSpace(line = sr.ReadLine()))
                {
                    string[] arr = line.Split('|');
                    if (arr.Length == 2 && !PokemonPathDic.ContainsKey(arr[0]))
                    {
                        PokemonPathDic.Add(arr[0], arr[1]);
                    }
                }
            }
            dgv_pokemon.DataSource = (from v in PokemonPathDic
                                      select new
                                      {
                                          key = v.Key,
                                          value = v.Value
                                      }).ToArray();

            using (StreamReader sr = new StreamReader(settingWuXiaPath, Encoding.Default))
            {
                string line = string.Empty;
                while (!string.IsNullOrWhiteSpace(line = sr.ReadLine()))
                {
                    string[] arr = line.Split('|');
                    if (arr.Length == 2 && !WuXiaPathDic.ContainsKey(arr[0]))
                    {
                        WuXiaPathDic.Add(arr[0], arr[1]);
                    }
                }
            }
            dgv_wuxia.DataSource = (from v in WuXiaPathDic
                                    select new
                                    {
                                        key = v.Key,
                                        value = v.Value
                                    }).ToArray();
        }

        private void dgv_pokemon_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                if (dgv_pokemon.Columns[e.ColumnIndex] is DataGridViewButtonColumn)
                {
                    string path = dgv_pokemon.Rows[e.RowIndex].Cells["path"].Value.ToString();
                    ProcessStartInfo info = new ProcessStartInfo();
                    info.FileName = Path.GetFileName(path);
                    info.Arguments = "cam cam";
                    info.WorkingDirectory = Path.GetDirectoryName(path);
                    info.CreateNoWindow = true;
                    info.WindowStyle = ProcessWindowStyle.Normal;
                    Process.Start(info);
                }
            }
        }

        private void dgv_wuxia_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                if (dgv_wuxia.Columns[e.ColumnIndex] is DataGridViewButtonColumn)
                {
                    string path = dgv_wuxia.Rows[e.RowIndex].Cells["wxPath"].Value.ToString();
                    ProcessStartInfo info = new ProcessStartInfo();
                    info.FileName = Path.GetFileName(path);
                    info.Arguments = "cam cam";
                    info.WorkingDirectory = Path.GetDirectoryName(path);
                    info.CreateNoWindow = true;
                    info.WindowStyle = ProcessWindowStyle.Normal;
                    Process.Start(info);
                }
            }
        }
    }
}
